package com.controller;

import com.exception.CustomException;
import com.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class BaseExceptionAdvice {
    /**
     * 自定义异常
     * */
    @ExceptionHandler(CustomException.class)
    public Result  handleCustomException(CustomException ex){
        return new Result(false,ex.getMessage());
    }

    /**
     *所有未知异常
     * */
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception ex){
        String message = ex.getMessage();
        if("Access is denied".equals(message)){
            return new Result(false,"权限不足");
        }
        return new Result(false,ex.getMessage());
    }
}
